import React, { Component } from "react";
import { Table, DatePicker } from "antd";
import locale from "antd/es/date-picker/locale/zh_CN";
import { accountCate } from "../../config/enums";
const { RangePicker } = DatePicker;
export default class Record extends Component {
  columns = [
    {
      title: "时间",
      dataIndex: "createTime",
      render: (e) => this.$dayjs(e).format("YYYY-MM-DD HH:mm"),
    },
    {
      title: "用户手机号",
      dataIndex: "userPhone",
    },
    {
      title: "金额",
      dataIndex: "money",
    },
    {
      title: "公链订单id",
      dataIndex: "orderId",
    },
    {
      title: "操作人",
      dataIndex: "adminName",
    },
    {
      title: "账户种类",
      dataIndex: "accountCate",
      render: (e) => accountCate[e],
    },
  ];
  state = {
    loading: false,
    multiData: [],
  };
  getData = async (time) => {
    this.setState({
      loading: true,
    });
    const res = await this.http("Remit", {
      start: time ? new Date(time[0]) : null,
      end: time && time[1] ? new Date(time[1]) : null,
    });
    res.data.dtos.forEach((i) => {
      i.accountCate = i.payRecord.accountCate;
      i.createTime = i.payRecord.createTime;
    });
    this.setState({
      loading: false,
      multiData: res.data.dtos,
    });
  };
  onOk = (value) => {
    this.getData(value);
  };
  componentDidMount() {
    this.getData();
  }
  render() {
    return (
      <div>
        <RangePicker
          locale={locale}
          style={{ margin: "20px" }}
          showTime={{ format: "HH:mm" }}
          format="YYYY-MM-DD HH:mm"
          onChange={this.onOk}
        />
        <Table
          rowKey={(data) => data.id}
          loading={this.state.loading}
          columns={this.columns}
          dataSource={this.state.multiData}
        />
      </div>
    );
  }
}
